package br.com.q7solucoes.lazerbrwebservicej.control;

import javax.servlet.ServletContext;

/**
 *
 * @author elenilson
 */
public class WebXmlController {
    
    private static WebXmlController instance;

    /*** Tags ***/
    public static final String TAG_MYSQL_DATABASE = "mysql-database";
    public static final String TAG_MYSQL_DATABASE_HOST = "mysql-database-host";
    public static final String TAG_MYSQL_DATABASE_CODE = "mysql-database-code";
    public static final String TAG_MYSQL_DATABASE_USER = "mysql-database-user";
    public static final String TAG_MYSQL_DATABASE_PASSWORD = "mysql-database-password";

    private ServletContext servletContext;

    public WebXmlController(ServletContext servletContext) {
        this.servletContext = servletContext;
    }
    
    /**
     * Retorna a unica instance do wrapper.
     *
     * @return a instancia do wrapper
     */
    public static WebXmlController getInstance(){
        return instance;
    }

    /**
     * Inicia as configuracoes do controller
     * 
     * @param servletContext o servlet
     * 
     * @return verdadeiro se foi possivel criar o controller e falso caso contrario ou ela ja tenha sido criado
     */
    public static boolean init(ServletContext servletContext){
        if(instance != null)
            return false;
        
        instance = new WebXmlController(servletContext);
        return true;
    }
    
    public synchronized String getMysqlDataBase() {
        return servletContext.getInitParameter(TAG_MYSQL_DATABASE);
    }

    public synchronized void setMysqlDataBase(String mysqlDataBase) {
        servletContext.setInitParameter(TAG_MYSQL_DATABASE, mysqlDataBase);
    }

    public synchronized String getMysqlDataBaseHost() {
        return servletContext.getInitParameter(TAG_MYSQL_DATABASE_HOST);
    }

    public synchronized void setMysqlDataBaseHost(String mysqlDataBaseHost) {
        servletContext.setInitParameter(TAG_MYSQL_DATABASE_HOST, mysqlDataBaseHost);
    }

    public synchronized String getMysqlDataBaseCode() {
        return servletContext.getInitParameter(TAG_MYSQL_DATABASE_CODE);
    }

    public synchronized String getMysqlDataBaseUser() {
        return servletContext.getInitParameter(TAG_MYSQL_DATABASE_USER);
    }

    public synchronized void setMysqlDataBaseUser(String mysqlDataBaseUser) {
        servletContext.setInitParameter(TAG_MYSQL_DATABASE_USER, mysqlDataBaseUser);
    }

    public synchronized void setMysqlDataBaseCode(String mysqlDataBaseCode) {
        servletContext.setInitParameter(TAG_MYSQL_DATABASE_CODE, mysqlDataBaseCode);
    }

    public synchronized String getMysqlDataBasePassword() {
        return servletContext.getInitParameter(TAG_MYSQL_DATABASE_PASSWORD);
    }

    public synchronized void setMysqlDataBasePassword(String mysqlDataBasePassword) {
        servletContext.setInitParameter(TAG_MYSQL_DATABASE_PASSWORD, mysqlDataBasePassword);
    }
}
